﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserControl_phong_tro_chi_tiet : System.Web.UI.UserControl
{
    #region Properties
    protected DataTable dtChiTiet;
    protected string strMaPhong;
    protected string strkv_ten;
    protected string strTieuDe;
    protected string strID_PT;
    protected string strNgayCapNhat;
    protected string strUs_ID;
    protected string strNguoiDang;
    protected string strEmail;
    protected string strLuotXem;
    protected string strDiaChi;
    protected string strPT_DienThoai;
    protected string strGiaPhong;
    protected string strDienTich;
    protected string strPhone;
    protected string strMotaCT;
    protected string strKinhDo;
    protected string strViDo;
    protected string strNoImg;
    protected string strAnh1;
    protected string strAnh2;
    protected string strAnh3;
    protected string strAnh4;
    protected string displayIMG;
    protected bool ConPhong;
    protected string strImageStatus;
    protected bool blMoiGioi;
    protected string strBgMoigioi;
    protected string strShowPhone;
    protected string strKV_NameEN;
    protected string strYoutube;
    protected int iCountImg = 0;
    protected string strhtml_imgs = "";
    protected string strhtml_imgs_thumb = "";
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        hd_KhuVuc.Value = clsCommon.fncGetRoute(this.Page, "param1");
        hd_KieuPhongTro.Value = clsCommon.fncGetRoute(this.Page, "userControl");
        xgetDetailPhongTro();
    }


    /// <summary>
    /// Lấy chi tiết phòng trọ, set title, description.
    /// Author:?
    /// Create Date:?
    /// </summary>
    private void xgetDetailPhongTro()
    {
        try
        {
            // Lấy mã phòng trọ trên URL
            string strTenPhong = clsCommon.fncGetRoute(this.Page, "param2");
            string[] strLstKey = strTenPhong.Split('-');
            strMaPhong = strLstKey[strLstKey.Length - 1];
            //
            dtChiTiet = clsPhongTro.PhongTro_FND(1,1,"",0,0,strMaPhong,"","",1).Tables[0];
            if (dtChiTiet == null) Response.Redirect("/");
            if (dtChiTiet.Rows.Count <= 0) Response.Redirect("/"); ;

            // DETAILS ROWS PHONGTRO
            #region DETAILSPHONGTRO
            strkv_ten = dtChiTiet.Rows[0]["kv_ten"].ToString();
            strTieuDe = dtChiTiet.Rows[0]["pt_tieude"].ToString();
            strID_PT = dtChiTiet.Rows[0]["PT_ID"].ToString();
            strNgayCapNhat = OsPortal.oStringHelper.ConvertDateTime_to_String(Convert.ToDateTime(dtChiTiet.Rows[0]["pt_ngaycapnhat"]), 1);
            strUs_ID = dtChiTiet.Rows[0]["us_id"].ToString().Trim();
            strNguoiDang = dtChiTiet.Rows[0]["us_hoten"].ToString().Trim();
            if (string.IsNullOrEmpty(strNguoiDang))
            {
                strNguoiDang = "<span style=\"color:red;\">★ khách vãng lai</span>";
            }

            strEmail = dtChiTiet.Rows[0]["us_email"].ToString().Trim();

            if (string.IsNullOrEmpty(strEmail))
            {
                strEmail = "★ khách vãng lai";
            }

            strLuotXem = dtChiTiet.Rows[0]["pt_luotxem"].ToString().Trim();
            strDiaChi = dtChiTiet.Rows[0]["pt_diachi"].ToString().Trim();
            strPT_DienThoai = dtChiTiet.Rows[0]["pt_dienthoai"].ToString().Trim();
            strGiaPhong = String.Format("{0:0,0 vnđ}", Convert.ToDouble(dtChiTiet.Rows[0]["pt_giaphong"]));
            strDienTich = String.Format("{0:0,0}", Convert.ToDouble(dtChiTiet.Rows[0]["pt_dientich"]));
            strKV_NameEN = dtChiTiet.Rows[0]["KV_TENKHONGDAU"].ToString().Trim().ToLower();
            strPhone = dtChiTiet.Rows[0]["us_dienthoai"].ToString().Trim();
            if (string.IsNullOrEmpty(strPhone))
            {
                strPhone = "★ Khách vãng lai";
            }

            //strMotaCT = System.Net.WebUtility.HtmlDecode(OsPortal.oStringHelper.ClearTagHTML(dtChiTiet.Rows[0]["pt_motachitiet"].ToString().Trim().Replace("\r\n","<br/>")));
            strMotaCT = dtChiTiet.Rows[0]["pt_motachitiet"].ToString().Trim().Replace("\r\n", "<br/>");

            if (strMotaCT.ToLower().Contains("<script>"))
            {
                strMotaCT = strMotaCT.ToLower().Replace("<script>", "");
            }

            strKinhDo = dtChiTiet.Rows[0]["pt_kinhdo"].ToString().Trim();
            strViDo = dtChiTiet.Rows[0]["pt_vido"].ToString().Trim();
            
            strhtml_imgs = "";
            strhtml_imgs_thumb = "";

            strAnh1 = dtChiTiet.Rows[0]["pt_anh1"].ToString().Trim();
            if (!string.IsNullOrEmpty(strAnh1)) {
                strhtml_imgs += "<img  src='/" + strAnh1 + "' alt='" + strTieuDe + " 1' />";
                strhtml_imgs_thumb += "<li class='active' rel='1'><img src='/" + strAnh1 + "' alt='" + strTieuDe + " 2' /></li>";
                iCountImg++;
            }
            strAnh2 = dtChiTiet.Rows[0]["pt_anh2"].ToString().Trim();
            if (!string.IsNullOrEmpty(strAnh2))
            {
                strhtml_imgs += "<img  src='/" + strAnh2 + "' alt='" + strTieuDe + " 3' />";
                strhtml_imgs_thumb += "<li rel='2'><img src='/" + strAnh2 + "' alt='" + strTieuDe + " 4' /></li>";
                iCountImg++;
            }
            strAnh3= dtChiTiet.Rows[0]["pt_anh3"].ToString().Trim();
            if (!string.IsNullOrEmpty(strAnh3))
            {
                strhtml_imgs += "<img  src='/" + strAnh3 + "' alt='" + strTieuDe + " 5' />";
                strhtml_imgs_thumb += "<li rel='3'><img src='/" + strAnh3 + "' alt='" + strTieuDe + " 6' /></li>";
                iCountImg++;
            }
            strAnh4 = dtChiTiet.Rows[0]["pt_anh4"].ToString().Trim();
            if (!string.IsNullOrEmpty(strAnh4))
            {
                strhtml_imgs += "<img  src='/" + strAnh4 + "' alt='" + strTieuDe + " 7' />";
                strhtml_imgs_thumb += "<li rel='4'><img src='/" + strAnh4 + "' alt='" + strTieuDe + " 7' /></li>";
                iCountImg++;
            }


            displayIMG = "block";
            if (strAnh1 == strNoImg && strAnh2 == strNoImg && strAnh3 == strNoImg && strAnh4 == strNoImg) { displayIMG = "none"; }

            ConPhong = Convert.ToBoolean(dtChiTiet.Rows[0]["pt_conphong"]); //get value here
            strImageStatus = "";
            if (ConPhong == true)
            {
                strImageStatus = "/Images/System/imgConPhong.jpg";
            }
            else
            {
                strImageStatus = "/Images/System/imgHetPhong.jpg";
            }

            blMoiGioi = Convert.ToBoolean(dtChiTiet.Rows[0]["us_moigioi"]);
            strBgMoigioi = "";
            if (blMoiGioi) strBgMoigioi = "/Images/System/moigioi.png";

            if (string.IsNullOrEmpty(strPT_DienThoai)) strShowPhone = strPhone;
            else strShowPhone = strPT_DienThoai;

            strYoutube = dtChiTiet.Rows[0]["pt_video_youtube"].ToString().Trim();
            #endregion

            #region SEO OPTIMAZE
            this.Page.Title = strTieuDe;
            this.Page.MetaDescription = System.Net.WebUtility.HtmlDecode(OsPortal.oStringHelper.fncCatChuoi(OsPortal.oStringHelper.ClearTagHTML(strMotaCT),157));
            this.Page.MetaKeywords = OsPortal.oStringHelper.TachChuoi(strTieuDe);
            #endregion
        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr("UserControl_phong_tro_chi_tiet", "xgetDetailPhongTro()", ex.ToString());
        }
    }


    /// <summary>
    /// Lấy mã phòng trọ trên url
    /// </summary>
    private void xGetParam()
    {
        string strKhuVuc = clsCommon.fncGetRoute(this.Page, "param1");
        string strTenPhong = clsCommon.fncGetRoute(this.Page, "param2");
        string[] strLstKey = strTenPhong.Split('-');
        strMaPhong = strLstKey[strLstKey.Length - 1];
        string strKieuPT = clsCommon.fncGetRoute(this.Page, "userControl");
        //Response.Write(strMaPhong);
    }
}